<template>
  <div class="base-map-resource-content">
    <div class="query-content">
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline backend-form"
      >
        <el-form-item label="模板名称">
          <el-input v-model="formInline.name" @change="onSubmit" />
        </el-form-item>
        <el-form-item class="backend-button">
          <el-button class="addButton" type="primary" @click="handleAddUser" v-if="currentUser?.hasPermission('yhzzgladd')">
            <i class="el-icon el-icon-plus"></i>
            {{ currentUser?.getButtonName('yhzzgladd') }}
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column align="center" label="序号" width="180">
          <template #default="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          label="模板名称"
          prop="title"
          show-overflow-tooltip
        />
        <el-table-column
          label="创建时间"
          prop="createdTime"
          show-overflow-tooltip
        />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button
              text
              type="text"
              style="padding: 0"
              @click="handleEditUserOld(scope.row)"
            >
            编辑
            </el-button>
            <el-popconfirm
              width="160px"
              confirm-button-text="确认"
              cancel-button-text="取消"
              icon-color="#626AEF"
              @confirm="handleDeleteClick(scope.row)"
              :title="'确认删除' + scope.row.title + '吗？'"
            >
              <template #reference>
                <el-button
                  text
                  type="text"
                  style="color: #fa3434; margin-left: 12px"
                  @click="handleDeleteClick(scope.row)"
                >
                  删除
                </el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      background
      layout="slot,prev, pager, next"
      :page-size="formInline.pageSize"
      :current-page="formInline.pageIndex"
      :total="total"
      @current-change="handlePageChange"
    >
      <template #default> 共{{ total }}个模板 </template>
    </el-pagination>
  </div>
</template>

<script setup lang="ts">
import { nextTick, onMounted, reactive, ref } from 'vue'
import { getTemplateList } from '@/api/screen-management/report-platform'
import type {
  templateQueryParams,
} from './interface'
import { getCurrentInstance } from 'vue'

const vm = getCurrentInstance()
const store = vm?.proxy.$store

const currentUser = store?.state?.user?.currentUser

const formInline = reactive<templateQueryParams>({
  pageIndex: 1,
  pageSize: 10,
  name: '',
})
const tableData = ref<any[]>([])
const total = ref(0)

const getUserList = () => {
  getTemplateList(formInline).then((res) => {
    const { success, data } = res
    if (success) {
      const { count, list } = data
      tableData.value = list
      total.value = count
    }
  })
}

onMounted(() => {
  getUserList()
})

const onSubmit = () => {
  formInline.pageIndex = 1
  getUserList()
}

const handleAddUser = () => {
}

const handleEditUserOld = (item: any) => {
}


const handlePageChange = (pageIndex: number) => {
  formInline.pageIndex = pageIndex
  getUserList()
}

const handleDeleteClick = (item: any) => {
  console.log(item)
}
</script>

<style lang="scss" scoped>
.base-map-resource-content {
  width: 100%;
  height: calc(100% - 27px);
  background-color: white;
  box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  display: flex;
  flex-direction: column;

  .query-content {
    padding-left: 20px;
    width: 100%;
    line-height: 62px;
    border-bottom: 1px solid #eeeff5;

    :deep(.el-form) {
      .el-form-item {
        margin-bottom: 0;

        .resetButton {
          width: 80px;
          height: 32px;
          color: #28b1e4;
          background: #ffffff;
          border: 1px solid #28b1e4;
          border-radius: 2px;
        }

        .queryButton {
          width: 80px;
          height: 32px;
          background: #28b1e4;
          border-radius: 2px;
        }
      }
    }
  }

  .addButton {
    margin-left: 20px;
    margin-top: 14px;
    margin-bottom: 14px;
    width: 100px;
    min-height: 32px;
    //background: #28b1e4;
    border-radius: 2px;
    //border: none;
    padding: 0;
  }

  .table {
    width: 100%;
    padding: 0 18px;
    overflow-y: auto;

    .userName {
      .item {
        margin-left: 6px;
      }
      :deep(.el-icon) {
        vertical-align: sub;

        .svg-icon {
          svg {
            width: 16px;
            height: 16px;
            color: #28b1e4;
          }
        }
      }
      :deep(.el-badge__content) {
        width: 12px;
        height: 13px;
        transform: translateY(85%) translateX(148%);
      }
    }

    :deep(.el-table__row--striped) {
      background: #f7f9fb;
    }
  }

  .el-pagination {
    margin-top: 20px;
    justify-content: end;
    margin-right: 18px;
    margin-bottom: 20px;
  }
}
</style>
